import { applyMiddleware, legacy_createStore as createStore } from 'redux';
import rootReducer from './reducer';
import thunk from 'redux-thunk';
import { composeWithDevTools } from 'redux-devtools-extension';
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';

const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)));

export default store;

//取出state 的类型
export type RootState = ReturnType<typeof store.getState>;

//取出dispatch的类型
export type AppDispatch = typeof store.dispatch;
export const useAppDispatch = () => useDispatch<AppDispatch>();
//取出getState的类型
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
